#include <stdlib.h>
#include "ExtremeC_examples_chapter7_1_engine.h"

typedef struct {
    //由于这个属性组合关系成立
    struct engine_t* engine;
} car_t;

car_t* car_new() {
    return (car_t*)malloc(sizeof(car_t));
}

void car_ctor(car_t* car) {
    //为 engine 对象分配内存
    car->engine = engine_new();
    
    //构造 engine 对象
    engine_ctor(car->engine);
}

//析构函数 Destructor
void car_dtor(car_t* car)
{
    //析构 engine 对象
    engine_dtor(car->engine);
    //释放为 engine 对象分配的内存
    free(car->engine);
}

//行为函数
void car_start(car_t* car) {
    engine_turn_on(car->engine);
}

void car_stop(car_t* car) {
    engine_turn_off(car->engine);
}

double car_get_engine_temperature(car_t* car) {
    return engine_get_temperature(car->engine);
}